package com.zyl.blog.tasks.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 异常处理工具类
 * @version v1.0
 * @ProjectName: Personal_Blog_Server
 * @Package: com.zyl.blog.tasks.utils
 * @ClassName: ExceptionUtil
 * @Author FinalFantasy
 * @Date 2025/8/13-08:40
 */
public class ExceptionUtil {

    /**
     * 获取异常堆栈信息
     */
    public static String getStackTrace(Throwable throwable) {

        if (throwable == null) {
            return "";
        }

        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw)) {
            throwable.printStackTrace(pw);
            return sw.toString();
        } catch (Exception e) {
            return "获取堆栈信息失败: " + e.getMessage();
        }
    }
}